import { createStore } from 'vuex'
import api from '../api/cart'
export default createStore({
  state:{cartCount: 0},
  mutations:{
    addCart (state, payload) {
        state.cartCount = payload.count;
        console.log("addCart",state.cartCount);
      }
  },
  actions:{
    async updateCart(ctx) {
      const { data } = await api.getCart();
      console.log("updateCart",data);
      ctx.commit('addCart', {
        count: data.length || 0
      })
    }
  },
  modules: {}
})